<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <script type="text/javascript">
      const _permute = (str) => {
        // 补全代码
        // var arr = string.split('')
        var result = []
        if (str.length > 1) {
          for (var i = 0; i < str.length; i++) {
            var left = str[0]
            var rest = str.slice(0, i) + str.slice(i + 1, str.length)
            var preResult = _permute(rest)
            for (var j = 0; j < preResult.length; j++) {
              var tmp = left + preResult[j]
              result.push(tmp)
            }
          }
        } else if (str.length == 1) {
          result.push(str)
        }
        return result
      }
      console.log(_permute('abc'))
    </script>
  </body>
</html>
